// 创建一个全局的工具类文件，例如 utils/watermark.js

export default {
  setWatermark(text) {
    const createWatermarkElement = () => {
      const watermarkView = document.createElement('view');
      watermarkView.style.position = 'fixed';
      watermarkView.style.top = '0';
      watermarkView.style.left = '0';
      watermarkView.style.width = '100%';
      watermarkView.style.height = '100%';
      watermarkView.style.zIndex = '9999';
      watermarkView.style.pointerEvents = 'none';
      watermarkView.style.display = 'flex';
      watermarkView.style.justifyContent = 'space-around';
      watermarkView.style.alignItems = 'space-around';
      watermarkView.style.backgroundColor = 'rgba(255, 255, 255, 0)';

      const watermarkText = document.createElement('text');
      watermarkText.style.color = 'rgba(0, 0, 0, 0.3)';
      watermarkText.style.fontSize = '14px';
      watermarkText.textContent = text;

      watermarkView.appendChild(watermarkText);

      return watermarkView;
    };

    const clientHeight = uni.getSystemInfoSync().windowHeight;
    const clientWidth = uni.getSystemInfoSync().windowWidth;

    const numHorizontal = Math.ceil(clientWidth / 100); // 根据需要调整间隔，这里假设每 100px 一个水印水平方向
    const numVertical = Math.ceil(clientHeight / 100); // 同理垂直方向

    for (let i = 0; i < numHorizontal; i++) {
      for (let j = 0; j < numVertical; j++) {
        const watermarkElement = createWatermarkElement();
        watermarkElement.style.top = `${j * 100}px`;
        watermarkElement.style.left = `${i * 100}px`;
        document.body.appendChild(watermarkElement);
      }
    }
  },
};